<template>
  <div id="app">
    <TodoList2 :todos="todos" :d="d"></TodoList2>
    <!--    <CreateTodo @add-todo="addTodo"></CreateTodo>-->
  </div>
</template>

<script>
import TodoList2 from './components/TodoList2'
import CreateTodo from './components/CreateTodo'
export default {
  components: {
    TodoList2,
    CreateTodo
  },
  data () {
    return {
      d: new Date().getFullYear() + '' +
        '-' + (new Date().getMonth() < 10 ? '0' : '') + (new Date().getMonth() + 1) + '' +
        '-' + (new Date().getDate() < 10 ? '0' : '') + new Date().getDate(),
      todos: [
        {
          title: '数学',
          time: null,
          done: '0'
        },
        {
          title: '睡觉',
          time: null,
          done: '0'
        },
        {
          title: '英语',
          time: null,
          done: '0'
        },
        {
          title: '起床',
          time: null,
          done: '0'
        },
        {
          title: '运动',
          time: null,
          done: '0'
        }
      ]
    }
  },
  methods: {
    addTodo (todo) {
      this.todos.push(todo)
      this.$swal('Success!', 'To-Do created!', 'success')
    }
  },
  created () {
    const _this = this
    _this.$axios.get('https://47744li119.goho.co/todos/show/' + _this.d).then(function (resp) {
      if (resp.data.length !== 0) {
        _this.todos = resp.data
      }
    })
  }
}
</script>

<style>
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  /*margin-top: 60px;*/
  background-color: lightblue;
}
</style>
